package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.ProductUnit;
import com.spzx.product.service.ProductUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;


@RestController
@RequestMapping("unit")
@Tag(name = "商品单位管理")
public class ProductUnitController extends BaseController {

    @Autowired
    ProductUnitService productUnitService;

    @Operation(summary = "获取商品单位分页列表")
    @GetMapping("list")
    public TableDataInfo list(ProductUnit productUnit){
       Page page =  productUnitService.selectProductUnitList(productUnit);
        return getDataTable(page);
    }
    @Operation(summary = "查询所有商品单位")
    @GetMapping
    public AjaxResult listAll(){
        return success(productUnitService.list());
    }
    @Operation(summary = "获取商品单位详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id")Long id){
        return success(productUnitService.getById(id));
    }

    @Operation(summary ="新增商品单位")
    @PostMapping
    public AjaxResult add(@RequestBody ProductUnit productUnit){

        return success(productUnitService.saveProductUnit(productUnit));
    }
    @Operation(summary = "修改商品单位")
    @PutMapping
    public AjaxResult update(@Validated @RequestBody ProductUnit productUnit){

        productUnitService.checkProductUnitName(productUnit);
        return success(productUnitService.updateById(productUnit));
    }

    @Operation(summary = "根据参数批量或单个删除商品单位")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids")List<Long> ids){
        return toAjax(productUnitService.removeBatchByIds(ids));
    }





}
